package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FaultSummary;
import com.ruoyi.system.service.IFaultSummaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 故障总表Controller
 *
 * @author ruoyi
 * @date 2025-01-20
 */
@RestController
@RequestMapping("/system/summary")
public class FaultSummaryController extends BaseController
{
    @Autowired
    private IFaultSummaryService faultSummaryService;

    /**
     * 查询故障总表列表
     */
    @PreAuthorize("@ss.hasPermi('system:summary:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultSummary faultSummary) {
        startPage();
        List<FaultSummary> list = faultSummaryService.selectFaultSummaryList(faultSummary);
        return getDataTable(list);
    }
    /**
     * 根据flag查询相同故障
     */
    @GetMapping("/flag")
    public List<FaultSummary> selectListByFlag(String finFlag,Long number) {
        return faultSummaryService.selectListByFlag(finFlag,number);
    }

    /**
     * 查询所有唯一的日期
     */
    @GetMapping("/allDate")
    public List<String> findUniqueDates()
    {
        return faultSummaryService.findUniqueDates();
    }

    /**
     * 导出故障总表列表
     */
    @PreAuthorize("@ss.hasPermi('system:summary:export')")
    @Log(title = "故障总表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultSummary faultSummary)
    {
        List<FaultSummary> list = faultSummaryService.selectFaultSummaryList(faultSummary);
        ExcelUtil<FaultSummary> util = new ExcelUtil<FaultSummary>(FaultSummary.class);
        util.exportExcel(response, list, "故障总表数据");
    }

    /**
     * 获取故障总表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:summary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(faultSummaryService.selectFaultSummaryById(id));
    }

    /**
     * 新增故障总表
     */
    @PreAuthorize("@ss.hasPermi('system:summary:add')")
    @Log(title = "故障总表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultSummary faultSummary)
    {
        return toAjax(faultSummaryService.insertFaultSummary(faultSummary));
    }

    /**
     * 修改故障总表
     */
    @PreAuthorize("@ss.hasPermi('system:summary:edit')")
    @Log(title = "故障总表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultSummary faultSummary)
    {
        return toAjax(faultSummaryService.updateFaultSummary(faultSummary));
    }

    /**
     * 删除故障总表
     */
    @PreAuthorize("@ss.hasPermi('system:summary:remove')")
    @Log(title = "故障总表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids)
    {
        return toAjax(faultSummaryService.deleteFaultSummaryByIds(ids));
    }
    /**
     * 去除故障
     */
	@GetMapping("/remove")
    public AjaxResult remove(Long id)
    {
        return toAjax(faultSummaryService.removeFaultSummaryById(id));
    }
}
